import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    detailArr: [],
    denglu: false,
  },

  mutations: {
    location(state,arr) {
      state.detailArr = arr
    },
    remove(state, index) {
      state.detailArr.splice(index, 1)
    },
    minus(state, index) {
      state.detailArr[index].num--
    },
    add(state, index) {
      state.detailArr[index].num++
    },
    detail(state, obj) {
      if (state.detailArr.length > 0) {
        if (state.detailArr.some(function (value) {
          return value.name == obj.name
        })) {
          state.detailArr.forEach(function (node) {
            if (node.name == obj.name) {
              node.num += obj.num
            }
          })
        } else {
          state.detailArr.push(obj)
        }
      } else {
        state.detailArr.push(obj)
      }
    },
    changedenglu(state) {
      state.denglu = true
    }
  },
  actions: {
  },
  modules: {
  }
})
